﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <link href="bootstrap.css" rel="stylesheet" />
    <link href="bootstrap-theme.css" rel="stylesheet" />
    <script src="jquery.js"></script>
    <script src="vue.js"></script>
    <script src="ModuleLoader.js"></script>
    <script src="FastHttpApi.js"></script>
    <script src="AdminController.js"></script>
    <script src="bootstrap.js"></script>
    <script src="md5.js"></script>
    <title>FastHttpApi Service Management</title>
    <style>
        pre {
            padding: 5px;
            margin: 5px;
        }

        .string {
            color: green;
        }

        .number {
            color: green;
        }

        .boolean {
            color: blue;
        }

        .null {
            color: magenta;
        }

        .key {
            color: red;
        }
    </style>
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container" slot="header">

        </div>
    </div>
    <div class="container bs-docs-container" style="padding-top:60px;">
        <div class="row">
            <div slot="mainBar">
            </div>

            <div id="apis" class="list-group">
            </div>
        </div>
    </div>
    <br />
    <br />
    <br />
    <br />
    <div class="navbar navbar-inverse navbar-fixed-bottom">
        <div class="container" style="color:aliceblue;text-align:center;" slot="footer">
        </div>
    </div>
    <script>
        var _lastitem;
        function showItem(item) {
            if (_lastitem) {
                $(_lastitem).hide();
            }
            _lastitem = item;
            $(_lastitem).show();
        }
        $(document).ready(function () {
            var i = 0;
            $.get("/_admin/listapi", function (result) {
                if (result.Code == 403) {
                    window.location.href = 'login.html';
                    return;
                }
                result.Data.forEach(function (v, i) {
                    var html = '<a href="javascript:void(0)" onclick="showItem(\'#api' + i + '\')" class="list-group-item"><b>' + v.Url + '</b>   ' + v.Remark + '</a>';
                    html += '<div id="api' + i + '" style="display:none;padding-left:20px;">'

                        + '<div class="bs-callout bs-callout-warning" id="callout-inputgroup-container-body"> \
                                                                                                             <h4>http </h4 > \
<span class="label label-default">Url:</span> \
                                                                            <pre>'+ v.Http.Url + '</pre> \
                                                                              <span class="label label-default">Post:</span> \
<pre>'+ (v.Http.Body ? v.Http.Body : 'null') + '</pre> \
<h4>WebSocket</h4 > \
<span class="label label-default">Send:</span> \
<pre>'+ v.WebSocket.Body + '</pre> \
                                                                                                                                                                                                      </div > '
                        + '</div >';

                    i++;
                    $('#apis').append(html);
                })

                $('pre').each(function () {

                    $(this).html(syntaxHighlight($(this).html()));
                });
            })
        })

        function syntaxHighlight(json) {
            if (typeof json != 'string') {
                json = JSON.stringify(json);
            }
            //json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');

            return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
                var cls = 'number';
                if (/^"/.test(match)) {
                    if (/:$/.test(match)) {
                        cls = 'key';
                    } else {
                        cls = 'string';
                    }
                } else if (/true|false/.test(match)) {
                    cls = 'boolean';
                } else if (/null/.test(match)) {
                    cls = 'null';
                }

                return '<span class="' + cls + '">' + match + '</span>';

            });
        }

    </script>
</body>
</html>